import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../utils/color_util/color_util.dart';
import '../utils/style_util/style_util.dart';
import '../widgets/dialog_widget/alerts_dialog_widget_util.dart';
import '../widgets/dialog_widget/text_dialog_widget_util.dart';
import '../widgets/text_widget/text_widget.dart';

/// @className : dialog_page
/// @date 2022/08/22 22:49 
/// @author : xiaohai
/// @description : 警告框

class DialogPage extends StatefulWidget {

  @override
  _DialogPageState createState() => _DialogPageState();

}

class _DialogPageState extends  State<DialogPage>{

  /// action列表
  late final List itemList = [{"title":"普通文本","index":1},{"title":"退出登录","index":2}];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(title: const Text("Dialog")),
      body: Builder(builder: (content){
        return ListView.builder(
            itemCount: itemList.length,
            itemBuilder: (BuildContext context, int index) {
              Map item = itemList[index];
              return  buildItemWidget(item["index"],item["title"]);
            });
      }),
    );
  }


  /// 构建item组件
  Widget buildItemWidget(int? index, String? title){
    return  InkWell(
      child: Container(
          child:Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                padding: EdgeInsets.only(left: 24.w,right: 24.w),
                alignment: Alignment.centerLeft,
                height: 120.w,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    textWidget(title, TS_000000_28_W4),
                    Image.asset("assets/images/right_arrow.png",
                        width: 48.w,
                        height: 48.w)
                  ],
                ),
              ),
              Container(
                  margin: EdgeInsets.only(left: 24.w),
                  color: ColorsUtil.hexColor(0xEBEDF2),height: 1.w)
            ],
          )
      ),
      onTap: (){
        if(index == 1){

          TextDialogWidgetUtil()
              .showtextDialogWidget(context, "玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明玩法说明", canceEvent: () {});

        }else if(index == 2){

          AlertsDialogWidgetUtil().showAlertsDialogWidget(
              context,
              "您确定要退出登录？",
              canceEvent: () {
                /// 取消点击事件
              },
              sureEvent: () async {
                /// 确认点击事件

              });

        }
      },
    );
  }



}